<template>
    <div class="app-container">
        <!--查询表单-->
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="volunteerQuery.userName" placeholder="用户名"/>
      </el-form-item>

      <el-form-item>
        <el-input v-model="volunteerQuery.stuId" placeholder="学号"/>
      </el-form-item>

      <el-form-item>
        <el-select v-model="volunteerQuery.status" clearable placeholder="用户状态">
          <el-option :value="1" label="激活"/>
          <el-option :value="0" label="未激活"/>
        </el-select>
      </el-form-item>

      <el-form-item label="添加时间">
        <el-date-picker
          v-model="volunteerQuery.begin"
          type="datetime"
          placeholder="选择开始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-form-item>
        <el-date-picker
          v-model="volunteerQuery.end"
          type="datetime"
          placeholder="选择截止时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

      <!-- 用户列表 -->
      <el-table
      :data="list"
      border
      fit
      highlight-current-row>

      <el-table-column
        label="序号"
        width="70"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="positionId" label="学号"/>

      <el-table-column prop="username" label="志愿者姓名" />

      <el-table-column prop="sex" label="性别" width="70">
        <template slot-scope="scope">
          {{ scope.row.sex===true?'男':'女' }}
        </template>
      </el-table-column>

      <el-table-column prop="telephone" label="电话"/>

      <el-table-column prop="email" label="邮箱"/>

      <el-table-column prop="status" label="用户状态" width="100">
        <template slot-scope="scope">
          {{ scope.row.status===true?'已激活':'未激活' }}
        </template>
      </el-table-column>

      <el-table-column prop="createTime" label="添加时间" />

      <el-table-column prop="updateTime" label="修改时间" />

      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/volunteer/edit/'+scope.row.id">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete" @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      background
      layout="prev, pager, next"
      style="padding: 30px 0; text-align: center;"
      @current-change="getList"
    />
    </div>
</template>
<script>
import volunteer from '@/api/management/volunteer'
export default {
    data(){
        return{
            list:null,//查询之后接口返回的集合
            page:1,
            limit:10,
            total:0,
            volunteerQuery:{}
        }
    },
    created(){//页面渲染之前执行
        this.getList()
        // console.log(this.list)
    },
    methods:{//创建具体方法，调用user.js中的方法
        getList(page = 1){
            this.page = page
            volunteer.getVolunteerListPage(this.page,this.limit,this.volunteerQuery)
                .then(response =>{
                    this.list = response.data.rows
                    this.total = response.data.total
                    // console.log(response)
                })
        },
        resetData(){
            //清空查询条件
            this.volunteerQuery = {}
            //查询所有数据
            this.getList()
        },
        removeDataById(id){
            this.$confirm('此操作将永久删除该志愿者, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //调用删除方法
                volunteer.deleteVolunteerById(id)
                    .then(response =>{
                        //提示删除成功
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        //刷新列表
                        this.getList()
                    })
            }).catch(() =>{
                this.$message({
                    type:'info',
                    message:'已取消删除'
                })
            })
        }
    }
}
</script>
